﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QLK.Database;
using QLK.Web.App_Code;
using QLK.Database.BLLs;

namespace QLK.Web
{
    public partial class CustomerDetails : System.Web.UI.Page
    {
        CustomerBLL CusBLL = new CustomerBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            Load_Data();
        }

        private void Load_Data()
        {
            grvCustomers.DataSource = CusBLL.CustomerGetAll();
            grvCustomers.DataBind();
        }

        protected void btnAddCus_Click(object sender, EventArgs e)
        {
            Response.Redirect(PageUrls.Categories);
        }

        protected void btnImages_Click(object sender, ImageClickEventArgs e)
        {
            GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
            int index = gvRow.RowIndex;

            ImageButton img = new ImageButton();
            Customer Cust = new Customer();
            Cust.CustomerID = int.Parse(img.CommandArgument);
            Cust.CustomerName = grvCustomers.Rows[index].Cells[2].Text.ToString();
            Cust.Address = grvCustomers.Rows[index].Cells[3].Text.ToString();
            Cust.PhoneNumber = grvCustomers.Rows[index].Cells[4].Text.ToString();

            Response.Redirect(string.Format("{0}?{1}={2}&{3}={4}&{5}={6}", PageUrls.Categories, Columns.CustomerID, Cust.CustomerID,
                Columns.CategoryName, Cust.CustomerName, Columns.Address, Cust.Address, Columns.PhoneNumber, Cust.PhoneNumber));
        }

        protected void grvCustomers_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grvCustomers.PageIndex = e.NewPageIndex;
            Load_Data();
        }
    }
}
